<?php // no direct access
defined('_JEXEC') or die('Restricted access');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
$Itemid = JRequest::getVar( 'Itemid', 0, 'get', 'int' );
JHTML::stylesheet('base.css', JURI::root().'components/com_simplelisting/css/');
JHTML::stylesheet('listing.css', JURI::root().'/components/com_simplelisting/css/themes/'.$this->select_theme.'/');
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration("
var ray={
randomPic:function(el,targ)
{
var img=document.getElementById(el).getElementsByTagName('img');
for(var i=0;i<img.length;i++)
img[i].onclick=function()
{
document.getElementById(targ).setAttribute('src',this.getAttribute('src'));
return false;
}
}
}
window.onload=function()
{
ray.randomPic('cw_gallery','default'); // ID of the ul element and the id of the target image
}
");
$doc->addScriptDeclaration("
        var RecaptchaOptions = {
        theme : '$this->select_captcha_theme',
        };
");

?>

<base href="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'; ?>">

<div id="listing_details"><!-- Start main container div-->
    <div id="listing_details_inner"><!-- Start inner div -->
        <div class="header"><!-- Start header container -->
           <table class="general_details">
                <tbody>
                   <tr>
                       <td class="cw_title_main">
                            <?php echo $this->simplelisting->name; ?>
                       </td>
                   </tr>

                </tbody>
           </table>
            <span class="cw_item_id">
                               <?php echo JText::_( 'LABEL_REF' ),": ", $this->simplelisting->id; ?>
            </span>
           <span id="icons_detail">
                <?php
                $link = "index.php?option=com_simplelisting&task=favourite&id=".$this->simplelisting->id;
                $uri = "index.php?option=com_simplelisting&task=show&cid[]=".$this->simplelisting->id;
                ?>
                <a href="<?php echo $link ?>" title="<?php echo JText::_('TT_FAV_LINK') ?>">
                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/fav-16.png' ?>" alt="Favourite"/></a>
           </span>
            <span id="cw_back_button_top">
            <input type="button" onClick="history.go(-1);return false;" value="<?php echo JText::_('BT_BACK'); ?>" class="button">
            </span>
            <div style="width:100%; height:5px;"></div>
        </div><!-- End header container -->

    <div class="container"><!-- Start image main container -->
	 <span id="image_main">
            <?php if ( is_file( JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ) ) : ?>
                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>" alt="Default" id="default">
            <?php else: ?>
                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/nolistings.gif'; ?>" alt="Default" id="default" width="400" />
            <?php endif; ?>
         </span>
    </div><!-- End image main container -->

    <div style="width:100%; height:10px;"></div>

    <div class="container"><!-- Start gallery container -->
        <span>
            <p id="cw_gallery">
                <?php if( is_file( JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ) ) : ?>
                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>" alt="myimage">
                <?php else: ?>
                <img src="<?php echo JURI::root().'/components/com_simplelisting/images/nolistings.gif'; ?>" alt="myimage" />
                <?php endif; ?>
                <?php
                    $TrackDirPath = JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/second/';
                    if ( !JFolder::exists($TrackDirPath) ) { JFolder::create($TrackDirPath); }
                    $TrackDir = opendir($TrackDirPath);
                    $count = 0;
                    while (($file = readdir($TrackDir)) !== false) {
                    if ($file == "." || $file == "..") { }
                    else {
                ?>
               <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/second/'.$file; ?>" alt="myimage" />
                <?php
                        }
                    }
                closedir($TrackDir);
                ?>
            </p>
        </span>
    </div><!-- End gallery container -->

    <div style="width:100%; height:10px;"></div>

    <table class="general_fields">
       <tbody>
           <tr>
               <td colspan="6" class="cw_title_extras">
                <?php echo JText::_('FT_LISTING_DESCRIPTION')?>
               </td>
           </tr>
           <tr>
               <td colspan="6" class="cw_title_separator"></td>
           </tr>
           <tr>
               <td align="justify">
                <?php echo $this->simplelisting->description; ?>
               </td>
           </tr>
       </tbody>
    </table>

    <div style="width:100%; height:10px;"></div>

    <table class="general_fields">
       <tbody>
            <tr>
              <td colspan="6" class="cw_title_extras">
                <?php echo JText::_('FT_LISTING_DETAILS')?>
              </td>
            </tr>
            <tr>
               <td colspan="6" class="cw_title_separator"></td>
            </tr>
            <?php if ( $this->params->get( 'show_price_admin' ) ) : ?>
                <?php if ( $this->params->get( 'show_price_detail' ) ) : ?>
                    <tr>
                       <?php if ( $this->params->get( 'price_label' ) ) : ?>
                           <td class="label">
                               <?php echo $this->price_label;?>
                           </td>
                       <?php else :?>
                           <td class="label">
                                <?php echo JText::_('LABEL_PRICE').': '?>
                           </td>
                       <?php endif ?>
                       <td class="content">
                           <?php $number = $this->simplelisting->price;
                                if ($this->currency_format==0) {
                                        $formatted_price = number_format($number);
                                } else if ($this->currency_format==1) {
                                        $formatted_price = number_format($number,3);
                                } else if ($this->currency_format==2) {
                                        $formatted_price = number_format($number, 2,', ',' ');
                                } else if ($this->currency_format==3) {
                                        $formatted_price = number_format($number, 2,'.','');
                                }
                                echo $this->currency,$formatted_price; ?>
                       </td>
                    </tr>
                <?php endif; ?>
            <?php endif; ?>

            <?php if ( $this->params->get( 'show_category_detail' ) ) : ?>
               <tr>
                   <?php if ( $this->params->get( 'category_label' ) ) : ?>
                       <td class="label">
                            <?php echo $this->category_label; ?>
                       </td>
                   <?php else :?>
                       <td class="label">
                            <?php echo JText::_('LABEL_CATEGORY').': '?>
                       </td>
                   <?php endif ?>
                       <td class="content">
                            <?php echo $this->escape($this->simplelisting->category); ?>
                       </td>
               </tr>
            <?php endif; ?>

            <?php if ( $this->params->get( 'show_type_detail' ) ) : ?>
                <tr>
                   <?php if ( $this->params->get( 'type_label' ) ) : ?>
                       <td class="label">
                            <?php echo $this->type_label; ?>
                       </td>
                   <?php else :?>
                       <td class="label">
                            <?php echo JText::_('LABEL_TYPE').': '?>
                       </td>
                   <?php endif ?>
                   <td class="content">
                        <?php echo $this->escape($this->simplelisting->type); ?>
                   </td>
               </tr>
            <?php endif; ?>

            <?php if ( $this->params->get( 'show_address_admin' ) ) : ?>
                <?php if ( $this->params->get( 'show_address_detail' ) ) : ?>
                   <?php if ( !empty($this->simplelisting->address) ) { ?>
                        <tr>
                           <?php if ( $this->params->get( 'address_label' ) ) : ?>
                               <td class="label">
                                    <?php echo $this->address_label; ?>
                               </td>
                           <?php else :?>
                               <td class="label">
                                    <?php echo JText::_('LABEL_ADDRESS').': '?>
                               </td>
                           <?php endif ?>
                            <td class="content">
                                <?php echo $this->simplelisting->address; ?>
                            </td>
                        </tr>
                    <?php } ?>
                <?php endif; ?>
            <?php endif; ?>

            <?php if ( $this->params->get( 'show_country_admin' ) ) : ?>
                <?php if ( $this->params->get( 'show_country_detail' ) ) : ?>
                    <?php if ( !empty($this->simplelisting->country) ) { ?>
                        <tr>
                           <?php if ( $this->params->get( 'country_label' ) ) : ?>
                               <td class="label">
                                    <?php echo $this->country_label; ?>
                               </td>
                           <?php else :?>
                               <td class="label">
                                    <?php echo JText::_('LABEL_COUNTRY').': '?>
                               </td>
                           <?php endif ?>
                            <td class="content">
                                <?php echo $this->escape($this->simplelisting->country); ?>
                            </td>
                        </tr>
                    <?php } ?>
                <?php endif; ?>
            <?php endif; ?>

           <?php if ( $this->params->get( 'show_extras_admin' ) ) : ?>
               <?php if ( $this->params->get( 'show_extras_detail' ) ) : ?>
                   <?php if ( !empty($this->simplelisting->extra) ) { ?>
                        <tr>
                           <?php if ( $this->params->get( 'extras_label' ) ) : ?>
                               <td class="label">
                                    <?php echo $this->extras_label; ?>
                               </td>
                           <?php else :?>
                               <td class="label">
                                    <?php echo JText::_('LABEL_EXTRAS').': '?>
                               </td>
                           <?php endif ?>
                           <td class="content">
                                <?php echo $this->escape($this->simplelisting->extra); ?>
                           </td>
                        </tr>
                    <?php } ?>
                <?php endif; ?>
            <?php endif; ?>

            <?php if ( $this->params->get( 'show_layout_admin' ) ) : ?>
                <?php if ( $this->params->get( 'show_layout_detail' ) ) : ?>
                    <?php if ( !empty($this->simplelisting->layout) ) { ?>
                        <tr>
                           <?php if ( $this->params->get( 'layout_label' ) ) : ?>
                               <td class="label">
                                    <?php echo $this->layout_label; ?>
                               </td>
                           <?php else :?>
                               <td class="label">
                                    <?php echo JText::_('LABEL_LAYOUT').': '?>
                               </td>
                           <?php endif ?>
                            <td class="content">
                                <?php echo $this->escape($this->simplelisting->layout); ?>
                            </td>
                        </tr>
                    <?php } ?>
                <?php endif; ?>
             <?php endif; ?>

             <?php if ( $this->params->get( 'show_facilities_admin' ) ) : ?>
                <?php if ( $this->params->get( 'show_facilities_detail' ) ) : ?>
                    <?php if ( !empty($this->simplelisting->facilities) ) { ?>
                        <tr>
                           <?php if ( $this->params->get( 'facilities_label' ) ) : ?>
                               <td class="label">
                                    <?php echo $this->facilities_label; ?>
                               </td>
                           <?php else :?>
                               <td class="label">
                                <?php echo JText::_('LABEL_FACILITIES').': '?>
                               </td>
                           <?php endif ?>
                            <td class="content">
                               <?php
                                $db =& JFactory::getDBO();
                                $query = "SELECT * FROM #__simplelisting_facilities";
                                $db->setQuery( $query );
                                $r = $db->loadObjectList();

                                    $facilities = array();
                                    if ( !empty($this->simplelisting->facilities) ) {
                                        $facilities = explode( ',' ,  $this->simplelisting->facilities );
                                    }
                                        foreach($r as $row){
                                           if ( in_array($row->id, $facilities) ) {
                                                echo $row->name.", ";
                                            }
                                        }
                                ?>
                            </td>
                        </tr>
                    <?php } ?>
                <?php endif; ?>
             <?php endif; ?>

            <?php if ( $this->params->get( 'show_date_detail' ) ) : ?>
                <tr>
                   <?php if ( $this->params->get( 'posted_label' ) ) : ?>
                       <td class="label">
                            <?php echo $this->posted_label; ?>
                       </td>
                   <?php else :?>
                       <td class="label">
                            <?php echo JText::_('LABEL_POSTED_DATE').': '?>
                       </td>
                   <?php endif ?>
                    <td class="content">
                        <?php echo JHTML::_('date',  $this->simplelisting->date_created,  JText::_('DATE_FORMAT_LC3') ) ?>
                    </td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
   <div style="width:100%; height:10px;"></div>
<?php if ( $this->params->get( 'show_contact_container' ) ) : ?>
   <table class="general_fields">
       <tbody>
            <tr>
                <td class="cw_title_extras">
                    <?php echo JText::_('FT_AUTHOR_DETAILS')?>
                </td>
            </tr>
            <tr>
                <td colspan="6" class="cw_title_separator"></td>
            </tr>
            <tr>
                <td>
                    <?php if ( $this->params->get( 'show_contact_form' ) ) : ?>
                    <div class="tools_contact_form"><!-- Start contact form container -->
                        <form action="" method="post" enctype="application/x-www-form-urlencoded">
                            <table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">
                                <tbody>
                                    <tr>
                                        <td height="30">
                                        <label id="namemsg" for="name"><?php echo JText::_('LABEL_CONTACT_FORM_NAME').': '?></label>
                                        <input type="text" name="name" id="name" value="<?php echo $this->escape(JRequest::getVar('name', '')) ?>" size="30" class="inputbox" /></td>
                                    </tr>
                                    <tr>
                                        <td height="30">
                                        <label id="emailmsg" for="email"><?php echo JText::_('LABEL_CONTACT_FORM_EMAIL').': '?></label>
                                        <input type="text" name="email" id="email" value="<?php echo $this->escape(JRequest::getVar('email', '')) ?>" maxlength="100"  class="inputbox" /></td>
                                    </tr>
                                    <tr>
                                        <td height="30">
                                        <label id="textmsg" for="text"><?php echo JText::_('LABEL_CONTACT_FORM_MESSAGE').': '?></label>
                                        <textarea name="e_message" id="e_message" rows="5" cols="30"  class="inputbox"><?php echo $this->escape(JRequest::getVar('e_message', '')) ?></textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2"></td>
                                    </tr>
                                </tbody>
                            </table>
                        <input type="hidden" name="subject" id="subject" value="<?php echo JText::_('EMAIL_SUBJECT').': '?> <?php echo $this->simplelisting->name," - ", JText::_( 'LABEL_REF' )," : ", $this->simplelisting->id; ?>" size="30"  class="inputbox" />
                        <input type="hidden" name="create_by" value="<?php echo $this->simplelisting->create_by ?>" />
                        <input type="hidden" name="task" value="sendmail"/>
                        <input type="hidden" name="option" value="<?php echo JRequest::getVar( 'option' );?>"/>
                        <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>  <br />
                        <?php echo JHTML::_('form.token'); ?>
                        <?php
                            global $mainframe;
                            $mainframe->triggerEvent('onCaptchaDisplay');
			?>
                        <br />
                        <input type="submit" value="<?php echo JText::_('BT_SEND') ?>" class="button" />
                    </form>
                </div><!-- End contact form container -->
                <?php endif; ?>
                <?php if ( $this->params->get( 'show_contact_details' ) ) : ?>
                <div class="tools_contact"><!-- Start contact info container -->
                    <table width="100%">
                        <tbody>
                            <tr>
                                <td>
                                    <br />
                                    <?php if ( $this->params->get( 'show_cont_name_detail' ) ) : ?>
                                        <div class="tools_contact_icon">
                                            <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/notebook-24.png'; ?>" width="24" height="24" alt="Contact">
                                            <?php echo $this->escape( $this->simplelisting->username); ?>
                                        </div>
                                    <?php endif; ?>

                                    <?php if ( $this->params->get( 'show_cont_ph_detail' ) ) : ?>
                                        <?php if ( !empty($this->simplelisting->tel) ) { ?>
                                            <div class="tools_contact_icon">
                                                <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/telephone-24.png'; ?>" width="24" height="24" alt="Telephone">
                                                <?php echo $this->escape( $this->simplelisting->tel); ?>
                                            </div>
                                        <?php } ?>
                                    <?php endif; ?>

                                    <?php if ( $this->params->get( 'show_cont_mob_detail' ) ) : ?>
                                        <?php if ( !empty($this->simplelisting->mobile) ) { ?>
                                            <div class="tools_contact_icon">
                                                <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/mobile-24.png'; ?>" width="24" height="24" alt="Mobile">
                                                <?php echo $this->escape( $this->simplelisting->mobile); ?>
                                            </div>
                                        <?php } ?>
                                    <?php endif; ?>

                                    <?php if ( $this->params->get( 'show_cont_fax_detail' ) ) : ?>
                                        <?php if ( !empty($this->simplelisting->fax) ) { ?>
                                            <div class="tools_contact_icon">
                                                <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/printer-24.png'; ?>" width="24" height="24" alt="Fax">
                                                <?php echo $this->escape( $this->simplelisting->fax); ?>
                                            </div>
                                        <?php } ?>
                                    <?php endif; ?>

                                    <?php if ( $this->params->get( 'show_cont_email_detail' ) ) : ?>
                                            <div class="tools_contact_icon">
                                                <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/mail-24.png'; ?>" width="24" height="24" alt="Email">
                                                <?php echo $this->escape( $this->simplelisting->email); ?>
                                            </div>
                                    <?php endif; ?>
                                    
                                    <?php if ( $this->params->get( 'show_cont_country_detail' ) ) : ?>
                                        <?php if ( !empty($this->simplelisting->usercountry) ) { ?>
                                            <div class="tools_contact_icon">
                                                <img style="margin-right:5px;" align="left" src="<?php echo JURI::root().'components/com_simplelisting/images/flag-24.png'; ?>" width="24" height="24" alt="Email">
                                                <?php echo $this->escape( $this->simplelisting->usercountry); ?>
                                            </div>
                                        <?php } ?>
                                    <?php endif; ?>

                                    <?php if ( $this->params->get( 'show_cont_misc_detail' ) ) : ?>
                                        <?php if ( !empty($this->simplelisting->misc) ) { ?>
                                            <div class="tools_contact_misc">
                                                <?php echo $this->escape( $this->simplelisting->misc); ?>
                                            </div>
                                        <?php } ?>
                                    <?php endif; ?>

                                    <br />
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div><!-- End contact info container -->
               <?php endif; ?>
            </td>
        </tr>
    </tbody>
</table>
<?php endif; ?>
<input type="hidden" name="option" value="com_simplelisting" />
<input type="hidden" name="view" value="listing" />
            <?php if ( $this->params->get( 'show_poweredby' ) ) : ?>
                <div class="cw_powerbyfront">
                    <span class="cw_powerbyfront"><?php echo JTEXT::_('POWEREDBY_MSG'); ?> <a href="http://www.celtaweb.com" target="_blank" title="CeltaWeb">CeltaWeb</a> </span>
                </div>
            <?php endif ?>
    </div><!-- listing_details_inner-->
</div><!-- listing_details-->
